import request from "../../../utils/request.ts";
import type {RoleResponseData, SetRoleData, User} from "./type.ts";

//@ts-ignore
enum API {
    //获取所有用户信息
    ALLUSER_URL = '/admin/acl/user/',
    //添加一个用户账号
    ADDUSER_URL = '/admin/acl/user/save',
    //更新一个用户账号
    UPDATEUSER_URL = '/admin/acl/user/update',
    //获取全部职位
    ALLROLESURL='/admin/acl/user/toAssign/',
    //给用户分配职位
    SETROLE_URL='/admin/acl/user/doAssignRole',
    //根据用户id单个删
    DELETEUSER_URL='/admin/acl/user/remove/',
    //根据用户id集合批量删
    DELETEALLUSER_URL='/admin/acl/user/batchRemove'
}

//获取所有有用户信息
//模糊查询用户username
export const reqUserInfo = (page: number, pageSize: number, username: string) => {
  return request.get(API.ALLUSER_URL + page + '/' + pageSize, {params: {username}})
}

//添加或更新用户账号
export const reqAddOrUpdateUser = (data: User) => {
  if (!data.id) {
      return request.post<any, any>(API.ADDUSER_URL, data);
  } else {
      return request.put<any, any>(API.UPDATEUSER_URL, data);
  }
}

//获取全部职位
export const reqAllRoles = (userId: number) => {
  return request.get<any, RoleResponseData>(API.ALLROLESURL + userId);
}

//给用户分配职位
export const reqSetUserRole = (data: SetRoleData) => {
    return request.post<any, any>(API.SETROLE_URL, data);
}

//根据用户id删除默一个用户
export const reqRemoveUser = (userId: number) => {
  return request.delete<any, any>(API.DELETEUSER_URL + userId);
}

//更具用户id批量删除
export const reqBatchUser = (userIds: number[]) => {
  return request.delete(API.DELETEALLUSER_URL, {data: userIds})
}


